<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加页面</title>
</head>
<body>
<form class="layui-form" lay-filter="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
				<div class="layui-form-item">
    				<label class="layui-form-label" title="手机号"> <text title="必填项" style="color:red;">*</text> 手机号</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="phone" id="phone" placeholder="请输入手机号" class="layui-input" lay-verify="required|phone">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="姓名"> <text title="必填项" style="color:red;">*</text> 姓名</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="name" id="name" placeholder="请输入姓名" class="layui-input" lay-verify="required">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="密码"> <text title="必填项" style="color:red;">*</text> 密码</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="password" id="password" placeholder="请输入密码" class="layui-input" lay-verify="required">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="重复密码"> <text title="必填项" style="color:red;">*</text> 重复密码</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="re_password" id="re_password" placeholder="请输入密码" class="layui-input" lay-verify="required">
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="性别"> <text title="必填项" style="color:red;">*</text> 性别</label>
    				<div class="layui-input-block">
            			<input type="radio" name="sex" id="sex-1" value="1" title="男"  />
						<input type="radio" name="sex" id="sex-2" value="2" title="女" checked="checked" />
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="身份"> <text title="必填项" style="color:red;">*</text> 身份 </label>
    				<div class="layui-input-block">
            			<select name="type" id="type" lay-verify="required" placeholder="请选择">
							<option value="">请选择</option>
							<option value="1">Boss</option>
							<option value="2">Leader</option>
							<option value="3">Phper</option>
							<option value="4">Gofer</option>
                        </select>
    				</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="身份证号码"> <text title="必填项" style="color:red;">*</text> 身份证号码</label>
    				<div class="layui-input-block">
            			<input autocomplete="off" type="text" name="id_card" id="id_card" placeholder="请输入身份证号码" class="layui-input" lay-verify="required|identity">
    				</div>
				</div>

				<!-- 新增组织下拉选项 -->
				<div class="layui-form-item">
					<label class="layui-form-label">组织</label>
					<div class="layui-input-block">
						<select name="org_id" lay-filter="organization">
							<option value="">请选择组织</option>
						</select>
					</div>
				</div>

				<div class="layui-form-item">
    				<label class="layui-form-label" title="状态"> <text title="必填项" style="color:red;">*</text> 状态</label>
    				<div class="layui-input-block">
            			<!-- 隐藏域设置开关未选中时需要传递的参数值 -->
                        <input type="hidden" name="status" id="status-0" value="0" />
                        <input type="checkbox" name="status" id="status-1" lay-skin="switch" lay-text="正常|封禁" value="1"  />
    				</div>
				</div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="add">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script>
    if(localStorage.getItem("staticDomain")){
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v=" + Date.now() + "'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v=" + Date.now() + "'><\/script>");
    }else{
        document.write("<link rel='stylesheet' href='/static/component/laytp/css/laytp.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v=" + Date.now() + "'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v=" + Date.now() + "'><\/script>");
    }
</script>
<script>
    layui.use(['laytp'],function(){

		// 动态加载组织数据
		facade.ajax({
			route: '/admin.org/index',
			successAlert: false
		}).done(function (res) {
			if (res.code === 0) {
				let select = $('select[name="org_id"]');
				res.data.forEach(function (item) {
					select.append(`<option value="${item.id}">${item.name}</option>`);
				});
				layui.form.render('select'); // 刷新下拉框样式
			}
		});


        layui.form.on('submit(add)', function(data){
            var btnAnim = layui.button.load({elem:$(this)});
            try{
                data = facade.setEditorField(data);
            }catch (e) {
                facade.error(e);
                return false;
            }
            facade.ajax({
                route:'/admin.students/add',
                data : data.field
            }).done(function(res){
                if(res.code === 0){
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reloadData("laytp-table");
                }
                btnAnim.stop();
            }).fail(function(){
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>